/*
#####################################################################
####################	   T R I B U I T 		#####################
#####################################################################

Copyright (C) 2010  Christoph Schnack, Berlin (Germany)

This file is part of Tribuit.

    Tribuit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Tribuit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Tribuit.  If not, see <http://www.gnu.org/licenses/>.


########################################################################
*/
package OtherDialogs;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import GuiTools.TribuitFrame;
import Mainframe.Mainframe;
import Settings.*;
import Storage.Storage;

/**
 * @author Christoph Schnack
 *
 */
public class Manual{
	public TribuitFrame manualFrame;
	Mainframe MAINFRAME;
	Storage MAINVOC;
	Settings SET;
	Language lang;
	JScrollPane jp;
	JEditorPane jep;

	public Manual(Mainframe mf,Storage st,Settings s){
		MAINFRAME = mf;
		SET = s;
		MAINVOC = st;
		lang = s.getLanguage();
		manualFrame = new TribuitFrame(lang.getManual());
		
		JPanel buttonPanel = new JPanel();
		JButton closeBtn = new JButton(lang.getClose());
		closeBtn.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				manualFrame.dispose();
			}
		});
		jep = new JEditorPane("text/html","<html>" +
				"<head>"+
					"<style type='text/css'>"+
						"p  {font-size: 12px;}"+
						"h1 {font-size: 20px;}"+
						"h2 {font-size: 15px;}"+
						"h3 {font-size: 13px;}"+
						"h4 {font-size: 13px;}"+
						"li {font-size: 12px;}"+
					"</style>"+
				"</head>"+
				"<body marginwidth='20'>"+
				"<h1 align='center'>"+lang.getManual().toUpperCase()+"</h1>"+
				"<br><ol type='I'>" +
					"<li>"+lang.getManualVocabulariesHeader()+
						"<ol>"+
							"<li><a href='#wordAdmin'>"+lang.getManualVocabularyAdministrationHeader()+"</a></li>" +
							"<li><a href='#words'>"+lang.getManualWordsHeader()+"</a></li>" +
							"<li><a href='#wordCheck'>"+lang.getManualWordCheckHeader()+"</a></li>" +
							"<li><a href='#wordList'>"+lang.getManualWordListHeader()+"</a></li>" +
							"<li><a href='#onLearning'>"+lang.getManualOnLearningWordsHeader()+"</a></li>" +
							"<li><a href='#phonetic'>"+lang.getPhonetic()+"</a></li>"+
						"</ol>"+
					"</li>"+
					"<li>"+lang.getManualPMHeader()+
						"<ol>"+
							"<li><a href='#collAdmin'>"+lang.getPictureAdministration()+"</a></li>" +
							"<li><a href='#pictureUnit'>"+lang.getManualPictureUnitHeader()+"</a></li>" +
							"<li><a href='#pmInterrogation'>"+lang.getManualPMInterrogationHeader()+"</a></li>" +
						"</ol>"+
					"</li>" +
					"<li>"+lang.getShortcuts()+
							"<ol>"+
							"<li><a href='#scMainWindow'>"+lang.getMainWindow()+"</a></li>" +
							"<li><a href='#scLookUpParameters'>"+lang.getLookupParameters()+"</a></li>" +
							"<li><a href='#scVocAdmin'>"+lang.getVocabularyAdministration()+"</a></li>" +
							"<li><a href='#scEditWord'>"+lang.getEditWord()+"</a></li>" +
						"</ol>"+
					"</li>"+"</ol>"+
					
					"<br><br><br><br><br><br><br><br>"+
					
					"<h1>"+lang.getManualVocabulariesHeader()+"</h1>"+
					"<br><br>"+
					
					"<a name='wordAdmin'></a>"+
					"<h2><u>"+lang.getManualVocabularyAdministrationHeader()+"</u></h2>"+
					"<p>"+lang.getManualVocabulariesText()+"</p>"+
					
					"<br><br>"+
					
					"<a name='words'></a>"+
					"<h2><u>"+lang.getManualWordsHeader()+"</u></h2>"+
					"<p>"+lang.getManualWordsText()+"</p>"+
					
					"<br><br>"+
					
					"<a name='wordCheck'></a>"+
					"<h2><u>"+lang.getManualWordCheckHeader()+"</u></h2>"+
					"<p>"+lang.getManualWordCheckText()+"</p>"+
					
					"<br><br>"+
					
					"<a name='wordList'></a>"+
					"<h2><u>"+lang.getManualWordListHeader()+"</u></h2>"+
					"<p>"+lang.getManualWordListText()+"</p>"+
					
					"<br><br>"+
					
					"<a name='onLearning'></a>"+
					"<h2><u>"+lang.getManualOnLearningWordsHeader()+"</u></h2>"+
					"<p>"+lang.getManualOnLearningWordsText()+"</p>"+
					
					"<br><br>"+
					
					"<a name='phonetic'></a>"+
					"<h1>"+lang.getPhonetic()+"</h1>"+
					"<p>"+lang.getManualPhoneticText()+"</p>"+
					
					"<br><br><br><br><br><br><br><br>"+
					
					"<h1>"+lang.getManualPMHeader()+"</h1>"+
					
					"<br><br>"+
					
					"<a name='collAdmin'></a>"+
					"<h2><u>"+lang.getPictureAdministration()+"</u></h2>"+
					"<p>"+lang.getManualCollectionAdministrationText()+"</p>"+
					
					"<br><br>"+
					
					"<a name='pictureUnit'></a>"+
					"<h2><u>"+lang.getManualPictureUnitHeader()+"</u></h2>"+
					"<p>"+lang.getManualPictureUnitText()+"</p>"+
					
					"<a name='pmInterrogation'></a>"+
					"<h2><u>"+lang.getManualPMInterrogationHeader()+"</u></h2>"+
					"<p>"+lang.getManualPMInterrogationText()+"</p>"+

					"<br><br><br><br><br><br><br><br>"+

					"<h1>"+lang.getShortcuts()+"</h1>"+
					
					"<br><br>"+

					"<a name='scMainWindow'><h2>"+lang.getMainWindow()+"</h2></a>"+
					"<table border='1'>" +
						"<tr><td><b>ALT + A</b></td><td>"+lang.getVocabularyAdministration()+"</td></tr>"+
						"<tr><td><b>ALT + W</b></td><td>"+lang.getMenuWordcheck()+"</td></tr>"+
					"</table>"+
					"<i>"+lang.getIfTFFocused()+":</i>"+
					"<table border='1'>" +
						"<tr><td><b>"+lang.getArrowUp()+"</b></td><td>"+lang.getManualOpenLookUpOptions()+"</td></tr>"+
					"</table>"+
						

					"<a name='scLookUpParameters'><h2>"+lang.getLookupParameters()+"</h2></a>" +
					"<table border='1'>" +
						"<tr><td><b>"+lang.getArrowUp()+"/"+lang.getArrowDown()+"</b></td><td>"+lang.getSwitchMethod()+"</td></tr>"+
						"<tr><td><b>"+lang.getCtrl()+" "+lang.getEnter()+"</b></td><td>"+lang.getAccept()+"</td></tr>"+
						"<tr><td><b>"+lang.getCtrl()+" "+"D</b></td><td>"+lang.getCancel()+"</td></tr>"+
					"</table>"+
					
					"<a name='scVocAdmin'><h2>"+lang.getVocabularyAdministration()+"</h2></a>" +
					"<table border='1'>" +
						"<tr><td><b>"+lang.getCtrl()+" N</b></td><td>"+lang.getAddWord()+"</td></tr>"+
						"<tr><td><b>"+lang.getCtrl()+" E</b></td><td>"+lang.getEditSelectedWord()+"</td></tr>"+
						"<tr><td><b>"+lang.getCtrl()+" X</b></td><td>"+lang.getCloseDialog()+"</td></tr>"+
						"<tr><td><b>"+lang.getCtrl()+" I</b></td><td>"+lang.getActivateFilter()+"</td></tr>"+
						"<tr><td><b>"+lang.getCtrl()+" T</b></td><td>"+lang.getActivateTermClassFilter()+"</td></tr>"+
						"<tr><td><b>"+lang.getCtrl()+" S</b></td><td>"+lang.getActivateSectionFilter()+"</td></tr>"+
						"<tr><td><b>"+lang.getCtrl()+" F</b></td><td>"+lang.getFocusTF()+"</td></tr>"+
						"<tr><td><b>"+lang.getCtrl()+" L</b></td><td>"+lang.getFocusList()+"</td></tr>"+
						"<tr><td><b>ALT + "+lang.getArrowLeft()+"</b></td><td>"+lang.getSortByLangA()+"</td></tr>"+
						"<tr><td><b>ALT + "+lang.getArrowRight()+"</b></td><td>"+lang.getSortByLangB()+"</td></tr>"+
						"<tr><td><b>ALT + "+lang.getArrowUp()+"/"+lang.getArrowDown()+"</b></td><td>"+lang.getSwitchVocabulary()+"</td></tr>"+
					"</table>"+
					
					
					"<a name='scEditWord'><h2>"+lang.getEditWord()+"</h2></a>" +
					"<table border='1'>" +
						"<tr><td><b>"+lang.getCtrl()+" Enter</b></td><td>"+lang.getAccept()+"</td></tr>"+
						"<tr><td><b>"+lang.getCtrl()+" D</b></td><td>"+lang.getCancel()+"</td></tr>"+
					"</table><br>"+
					"<i>"+lang.getUsingShiftTheseCommandsWorkForWordB()+"</i>"+
					"<table border='1'>" +
						"<tr><td><b>"+lang.getCtrl()+" N</b></td><td>"+lang.getNewMeaningForWord()+"</td></tr>"+
						"<tr><td><b>"+lang.getCtrl()+" S</b></td><td>"+lang.getEditSynonyms()+"</td></tr>"+
						"<tr><td><b>ALT + "+lang.getArrowLeft()+"/"+lang.getArrowRight()+"</b></td><td>"+lang.getSwitchDisplayedMeaning()+"</td></tr>"+
						"<tr><td><b>ALT + "+lang.getArrowUp()+"/"+lang.getArrowDown()+"</b></td><td>"+lang.getSwitchTermClass()+"</td></tr>"+
					"</table>"+
					
					
					"<br><br></body></html>"
		);
		jep.setEditable(false);
		jep.addHyperlinkListener(new HyperlinkListener() {
			public void hyperlinkUpdate(HyperlinkEvent hev) {
				try {
					if (hev.getEventType() == HyperlinkEvent.EventType.ACTIVATED)jep.scrollToReference(hev.getDescription().substring(1, hev.getDescription().length()));
				}
				catch (Exception e) {e.printStackTrace();}
			}
		});
		jep.setLayout(new FlowLayout(FlowLayout.CENTER,100,100));
		jp = new JScrollPane(jep);
		jp.setPreferredSize(new Dimension(500,500));
		buttonPanel.add(closeBtn);
		jp.getVerticalScrollBar().setUnitIncrement(20);
		manualFrame.getContentPane().add(BorderLayout.CENTER,jp);
		manualFrame.getContentPane().add(BorderLayout.SOUTH,buttonPanel);
		manualFrame.showUpAt(mf);
		manualFrame.setResizable(true);
		manualFrame.pack();
		manualFrame.setVisible(true);
		SwingUtilities.invokeLater(new Runnable(){
			public void run() {
				jp.getViewport().setViewPosition(new Point(0, 0));
			}
		});
	}
}
